import { Request, Response } from 'express'
import { notificationService } from '../services/notification'

export const getNotifications = async (req: Request, res: Response) => {
  try {
    const { page, limit } = req.query
    const notifications = await notificationService.getUserNotifications(
      req.user!.id,
      Number(page),
      Number(limit)
    )
    res.json(notifications)
  } catch (error) {
    res.status(500).json({ message: error.message })
  }
}

export const getUnreadCount = async (req: Request, res: Response) => {
  try {
    const count = await notificationService.getUnreadCount(req.user!.id)
    res.json({ count })
  } catch (error) {
    res.status(500).json({ message: error.message })
  }
}

export const markAsRead = async (req: Request, res: Response) => {
  try {
    const { notificationIds } = req.body
    const result = await notificationService.markAsRead(req.user!.id, notificationIds)
    res.json(result)
  } catch (error) {
    res.status(500).json({ message: error.message })
  }
}

export const deleteNotifications = async (req: Request, res: Response) => {
  try {
    const { notificationIds } = req.body
    const result = await notificationService.deleteNotifications(req.user!.id, notificationIds)
    res.json(result)
  } catch (error) {
    res.status(500).json({ message: error.message })
  }
}
